/**
 * v-hasPermi 操作权限处理
 * Copyright (c) 2019 ruoyi
 */

import useUserStore from '@/store/modules/user'
import auth from '@/plugins/auth.js'
export default {
	mounted(el, binding, vnode) {
		const {
			arg,
			value
		} = binding
		const all_permission = "*:*:*";
		const permissions = useUserStore().permissions
		if (value && value instanceof Array && value.length > 0) {
			const permissionFlag = value
			let hasPermissions = false;
			switch (arg) {
				case 'or':
					hasPermissions = auth.hasPermiOr(permissions);
					break;
				case 'and':
					hasPermissions = auth.hasPermiAnd(permissions);
					break;
				default:
					hasPermissions = auth.hasPermi(permissions);
					break;
			}
			if (!hasPermissions) {
				el.parentNode && el.parentNode.removeChild(el)
			}
		} else {
			throw new Error(`请设置操作权限标签值`)
		}
	}
}